﻿using System.Windows;
using System.Windows.Controls;
using ZFCNew.Controls;
using ZFCNew.ViewModels;
using ZFCNew.ZfcServiceReference;
using System;
using System.Linq;

namespace ZFCNew.Views
{
    public partial class TeamView : UserControl
    {
        public TeamView()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(TeamView_Loaded);
        }

        void TeamView_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (var t in TeamHolder.Children)
            {
                ((RadioButton)t).Checked += new RoutedEventHandler(TeamView_Checked);
            }
        }

        void TeamView_Checked(object sender, RoutedEventArgs e)
        {
            ((TeamModel)LayoutRoot.DataContext).SelectedTeam = ((Control)sender).DataContext as Team;
        }

        private void OpenGroupStanding(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                TeamModel model = ((TeamModel)LayoutRoot.DataContext);
                var gs = new GroupStanding();
                var data = from row in model.Teams
                           where row.Group == model.SelectedTeam.Group
                           select new GroupData
                                      {
                                          Team = row.Name,
                                          MP = row.MP,
                                          W=row.W,
                                          D=row.D,
                                          L=row.L,
                                          GF = row.GF,
                                          GA=row.GA,
                                          Pts = row.Pts
                                      };

                gs.DataContext = data;
                gs.GroupTB.Text = model.SelectedTeam.Group;
                var win = new ZfcWindow();
                win.VerticalAlignment = VerticalAlignment.Top;
                win.Margin = new Thickness(0, 100, 0, 0);
                win.Content = gs;
                win.Show();
            }
            catch (Exception)
            {
                
            }
        	 
        }
    }


    public class GroupData
    {
        public string Team { get; set; }
        public int MP { get; set; }
        public int W { get; set; }
        public int D { get; set; }
        public int L { get; set; }
        public int GF { get; set; }
        public int GA { get; set; }
        public int Pts { get; set; }
    }


}
